package com.example.repair

import com.blankj.utilcode.util.SPUtils
import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.HttpType
import com.example.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
import javax.inject.Inject
@HiltViewModel
class RepairViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<RepairIntent>() {
    override fun handleIntent(it: RepairIntent) {
        when(it){
            RepairIntent.repair -> {
                httpRequest(apiService.repair())
            }

            is RepairIntent.upload -> {
                httpRequest(apiService.upload(toPart(it.path,it.filename),"repair",SPUtils.getInstance().getInt("uid").toString()))
            }

            is RepairIntent.repairAdd -> {

                httpRequest(apiService.repairAdd(toBody(it.item)),HttpType.ADD)
            }

            is RepairIntent.repairUpdare -> {
                httpRequest(apiService.repairUpdate(it.rid,toBody(it.item)),HttpType.UPDATE)
            }
        }
    }
}